package sw.controller;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class RootController {
	
	//应用根请求
	@GetMapping("/")
	public String showIndexPage(){
		//model.addAttribute("today", new Date());
		return "index"; //返回index.html视图
	}
	
	@GetMapping("/html")
	public String newRequest(){
		
		return "html1";  //返回html1视图
	}
	
	
	//请求返回一个数组
	@GetMapping("/array")
	@ResponseBody
	public String newArray(){
		String[] scores={"ont","two","three"};
		return scores[1]; 
	}
	
	//请求返回2个参数
	@GetMapping("/add")
	//@ResponseBody
	public String NewAdd(Double data1,Double data2,String operator,Model model){
		Double result = 0d;
		switch(operator){
			case "+" : result = data1 + data2;break;
			case "-" : result = data1 - data2;break;
			case "*" : result = data1 * data2;break;
			case "/" : result = data1 / data2;break;
		}
		//Double result=data1+data2; 
		model.addAttribute("data1", data1);
		model.addAttribute("result", result);
		model.addAttribute("data2", data2);
		model.addAttribute("operator", operator);
		return "/html1";
	}
}
